console.log(THREE);  //threejs 全局对象
 
//1.渲染器
// let renderer = new THREE.WebGLRenderer({
//     canvas:document.querySelector('#canvas')
// });

let renderer = new THREE.WebGLRenderer({
    antialias:true
});
//设置渲染屏幕的尺寸
renderer.setSize(window.innerWidth,window.innerHeight);
//canvas添加到body里
document.body.appendChild(renderer.domElement);

console.log(renderer.domElement);

//2.创建场景  == 摄影棚  放置物体、灯光和摄像机的地方。
let scene = new THREE.Scene();

//3.创建相机  透视相机
let camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,1000);

//设置相机位置
camera.position.z = 30;
camera.position.y = 15;
camera.position.x = -5;
//相机拍场景的中心
camera.lookAt(scene.position)
//相机添加到场景
scene.add(camera);

//4.物品

//4.1创建一个平面
let planeGeometry = new THREE.PlaneGeometry(20,10);
let planeMaterial = new THREE.MeshBasicMaterial({
    color:0xcccccc
})
let plane = new THREE.Mesh(planeGeometry,planeMaterial);
plane.rotation.x = -0.5*Math.PI;
plane.position.x = 5;
scene.add(plane);

//4.2创建几何体  骨架
let boxGeometry = new THREE.BoxGeometry(3,3,3);
//创建材质
let material = new THREE.MeshBasicMaterial({
    color:0xff0000,
    // wireframe:true
}) 
//创建物品
let box = new THREE.Mesh(boxGeometry,material);
//设置物品的位置
box.rotation.y = 15;
box.position.y = 2;
//添加到场景中
scene.add(box);

//4.3创建球体

let sphereGeometry= new THREE.SphereGeometry(2,20,20);

//创建材质
let sphereMaterial = new THREE.MeshBasicMaterial({
    color:0x00ff00,
    // wireframe:true
}) 

let sphere = new THREE.Mesh(sphereGeometry,sphereMaterial);

sphere.position.x = 6;
sphere.position.y = 2;

scene.add(sphere);

//4.4 圆柱体

let cylinderGeometry = new THREE.CylinderGeometry(2,2,7,20,3);

let cylinderMaterial = new THREE.MeshLambertMaterial({
    color:0x00f0ff
})

let cylinder = new THREE.Mesh(cylinderGeometry,cylinderMaterial);

cylinder.position.x = 12
cylinder.position.y = 4;

scene.add(cylinder)


//添加辅助线
let axes = new THREE.AxesHelper(30);
scene.add(axes);

//划线

//自己定义几何体
// let geometry = new THREE.Geometry();

// let point1 = new THREE.Vector3(4,0,0);

// let point2 = new THREE.Vector3(4,5,0);

// geometry.vertices.push(point1);
// geometry.vertices.push(point2);

// let lineMaterial = new THREE.LineBasicMaterial({
//     color: 0xff00f0,
//     linewidth:1
// });

// let line = new THREE.Line(geometry,lineMaterial);

// scene.add(line);

let light = new THREE.DirectionalLight({
    color:0xff0000
})

// light.position.y = 15;
light.position.x = 5;
light.position.z = 5;
scene.add(light);

//进行渲染
renderer.render(scene,camera);





